/**
 * merge level=60
 */
Ext.define('Jfok.system.System', {

	viewport : null,

	// 金额单位,三个用到的变量
	monetary : '万元',
	monetaryUnit : 10000,
	monetaryUnitText : '万',

	constructor : function(v) {
		this.pageSize = parseInt(Cookies.get('pagesize', '20'));
		Ext.apply(this, v);
		this.tf_previewExts = this.tf_previewExts.split(','); // 可以在附件中预览的文件的后缀名的数组
	},

	getViewport : function() {
		return this.viewport;
	},

	setViewport : function(v) {
		this.viewport = v;
	},

	// 最大打开的 tab 数
	getMaxTab : function(){
		var s = Cookies.get('maxtab', 8);
		return parseInt(s);
	},
	
	// 保存到session中
	setMaxTab : function(v) {
		Cookies.set('maxtab', ''+v);
	},
	
	getAutoOpenModules : function() {
		var s = Cookies.get('autoopen', '');
		return s.length > 1 ? s.split(';') : [];
	},
	
	// 模块是否自动打开
	isModuleAutoOpen : function(moduleName) {
		var s = Cookies.get('autoopen', '');
		var modules = s ? s.split(';') : [];
		var have = false;
		Ext.each(modules, function(module) {
					if (module == moduleName)
						have = true;
				});
		return have;
	},

	// 新增一个模块到自动打开的cookies中去
	addModuleToAutoOpen : function(moduleName) {
		var s = Cookies.get('autoopen', '');
		var modules = s ? s.split(';') : [];
		var have = false;
		Ext.each(modules, function(module) {
					if (module == moduleName)
						have = true;
				});
		if (!have) {
			modules.push(moduleName);
			Cookies.set('autoopen', modules.join(';'));
		}
	},

	// 删除一个模块到自动打开的cookies中去
	deleteModuleToAutoOpen : function(moduleName) {
		var s = Cookies.get('autoopen', '');
		var modules = s ? s.split(';') : [];
		var pos = -1;
		Ext.each(modules, function(module, index) {
					if (module == moduleName) {
						pos = index;
						return false;
					}
				});
		if (pos != -1) {
			modules.splice(pos, 1);
			Cookies.set('autoopen', modules.join(';'));
		}
	},

	smileInfo : function(text, title) {

		Ext.create('Jfok.lib.Notification', {
					title : title ? title : '提醒信息',
					position : 'tr',
					width : 300,
					slideInDuration : 800,
					slideBackDuration : 1500,
					iconCls : 'ux-notification-icon-smile',
					autoCloseDelay : 3000,
					slideInAnimation : 'elasticIn',
					slideBackAnimation : 'elasticIn',
					html : text
				}).show();
	},

	warnInfo : function(text, title) {
		Ext.create('Jfok.lib.Notification', {
					title : title ? title : '提示信息',
					position : 'tr',
					width : 300,
					slideInDuration : 800,
					slideBackDuration : 1500,
					iconCls : 'ux-notification-icon-warn',
					autoCloseDelay : 3000,
					slideInAnimation : 'elasticIn',
					slideBackAnimation : 'elasticIn',
					html : text
				}).show();

	},

	errorInfo : function(text, title) {

		Ext.create('Jfok.lib.Notification', {
					title : title ? title : '错误提示',
					position : 'tr',
					useXAxis : true,
					width : 300,
					slideInDuration : 800,
					slideBackDuration : 1500,
					iconCls : 'ux-notification-icon-error',
					autoCloseDelay : 3000,
					slideInAnimation : 'elasticIn',
					slideBackAnimation : 'elasticIn',
					html : text
				}).show();
	},

	defaultRenderer : function(val, rd, model, row, col, store, gridview) {
		return filterTextSetBk(store, val);
	},

	dateRenderer : function(val, rd, model, row, col, store, gridview) {
		return '<span class="datecolor">'
				+ filterTextSetBk(store, Ext.util.Format.date(val, 'Y-m-d'))
				+ '</span>';
	},

	datetimeRenderer : function(val, rd, model, row, col, store, gridview) {
		return '<span class="datecolor">'
				+ filterTextSetBk(store, Ext.util.Format.date(val, 'Y-m-d H:i:s'))
				+ '</span>';
	},

	intRenderer : function(val, rd, model, row, col, store, gridview) {
		return '<span style="color:#00C;float:right;">'
				+ (val == 0 ? '' : filterTextSetBk(store, '' + val)) + '</span>';
	},

	booleanTextRenderer : function(val) {
		return (val ? '是' : ' ');
	},

	moneyRenderer : function(v) {
		if (v == 0)
			return '';
		v = v / Jfok.system.monetaryUnit;
		v = (Math.round((v - 0) * 100)) / 100;
		v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v
				+ "0" : v);
		v = String(v);
		var ps = v.split('.');
		var whole = ps[0];
		var sub = ps[1] ? '.' + ps[1] : '.00';
		var r = /(\d+)(\d{3})/;
		while (r.test(whole)) {
			whole = whole.replace(r, '$1' + ',' + '$2')
		}
		v = whole + sub;
		var r = '';
		if (v.charAt(0) == '-') {
			r = '-' + v.substr(1) + Jfok.system.monetaryUnitText
		} else
			r = "" + v + Jfok.system.monetaryUnitText;
		return '<span style="color: #00C;float:right;">' + r + '</span>'
	},

	percentRenderer1 : function(v,rd,model) {
		return '<span style="color: #00C;float:right;">' + (v + ' %') + '</span>'
	},
	
	percentRenderer : function(v, rd, model) {
//		if (!model.getIdValue())
//			return ;
		var v1 = v > 100 ? 100 : v;
		v1 = v1 < 0 ? 0 : v1;
		var v2 = parseInt(v1 * 2.55).toString(16);
		if (v2.length == 1)
			v2 = '0' + v2;
		return String
				.format(
						'<div>'
								+ '<div style="float:left;border:1px solid #008000;height:15px;width:100%;">'
								+ '<div style="float:left;text-align:center;width:100%;color:blue;">{0}%</div>'
								+ '<div style="background: #FAB2{2};width:{1}%;height:13px;"></div>'
								+ '</div></div>', v, v1, v2);
	},
	/**
	 * 对于manytoone字段，在其namefield上加一个超链，点击可以显示记录
	 */
	manytoOneFieldRenderer : function(val, rd, model, row, col, store, gridview) {
		var result = val;
		try {
			var column = gridview.headerCt.columnManager.columns[col];
			// console.log(column.moduleName + ';'+
			// model.data[column.manytooneIdName]+","+column.manytooneIdName);
			// console.log(model);
			var id = model.data[column.manytooneIdName];
			if (id == undefined)
				id = model.raw[column.manytooneIdName];
			if (id)
				result = '<span class="gridNameField">'
						+ '<a onclick="javascript:__smr(\'' + column.moduleName + '\',\''
						+ id + '\');return false;" href="#">' + filterTextSetBk(store, val)
						+ '</a></span>';
			else
				return filterTextSetBk(store, val);
		} catch (err) {
		}
		return result;
	}

})